<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">商户管理</div>
        <{include file= "Restaurant/nav.html"}>
        <div class="filedSet" style="padding-bottom: 0;">
            <div class="search">
                <form action="" class="ui-form reportForm" method="get" id="searchForm">
                    <input name="m" type="hidden" value="<{$module}>">
                    <input name="c" type="hidden" value="<{$controller}>">
                    <input name="a" type="hidden" value="<{$action}>">

                    <input name="p" id="page" type="hidden" value="<{$page|default:1}>">
                    <input name="limit" id="limit" type="hidden" value="<{$limit|default:10}>">
                    <!--<input name="ofield" id="ofield" type="hidden" value="<{$ofield}>">-->
                    <!--<input name="otype"  id="otype"  type="hidden" value="<{$otype}>">-->

                    <div class="ui-form-item inline-block">
                        <label class="ui-label">时间段</label>
                        <input type="text" name="startDate" id="startDate" value="<{$startDate}>" onfocus="WdatePicker({maxDate: new Date(),dateFmt:'yyyy-MM'})" class="ui-text startDate" readonly/>
                    </div>
                    <div class="ui-form-item inline-block">
                        <label class="ui-label">—&nbsp;&nbsp;&nbsp;</label>
                        <input type="text" name="endDate" id="endDate" value="<{$endDate}>" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}',dateFmt:'yyyy-MM'})" class="ui-text endDate" readonly/>
                    </div>
                    <div class="ui-form-item inline-block">
                        <label class="ui-label">商户</label>
                        <select class="ui-select" name="restaurant" onchange="ajaxGetRSRelated(this)">
                            <option value="-1">全部</option>
                            <{html_options options=$restaurant selected=$selectedRestaurant}>
                            <option value="0" <{if $selectedRestaurant==0}>selected<{/if}>>不限商户</option>
                        </select>
                    </div>
                    <div class="ui-form-item inline-block">
                        <label class="ui-label">门店</label>
                        <select class="ui-select" name="store" id="relatedStore">
                            <option value="0">全部</option>
                            <{html_options options=$store selected=$selectedStore}>
                        </select>
                    </div>
                    <div class="ui-form-item inline-block">
                        <button type="submit" class="ui-button" onclick="LayerShow();">查询</button>
                        <button type="button" onclick="exportData();" class="ui-button">导出Excel</button>
                    </div>
                </form>
            </div>
        </div>

        <!--表格内容-->
        <div class="mainGrid">
            <table class="ui-table ui-body">
                <thead>
                <tr>
                    <th class="pct10">月份</th>
                    <th class="pct10">商家</th>
                    <th class="pct10">门店</th>
                    <th class="pct10">卡券名</th>
                    <th class="pct10">卡券类型</th>
                    <th class="pct10 last-col">核销量</th>
                </tr>
                </thead>
                <tbody>
                <{foreach from = $list item=item}>
                <tr>
                    <td><{$item.addTime|date_format:"%Y-%m"}></td>
                    <td><{$item.restaurantName}></td>
                    <td><{$item.verificationStoreName}></td>
                    <td><{$item.cardTitle}></td>
                    <td><{$cardType[$item.cardType]}></td>
                    <td><{$item.consumeNum}></td>
                </tr>
                <{/foreach}>
                </tbody>
            </table>
        </div>

        <!--分页-->
        <div class="pagination">
            <{include file="Public/page.html"}>
        </div>
    </div>
</div>
</body>
<{include file="Public/foot.html" }>
<script>
    //获取商户和门店关联
    function ajaxGetRSRelated(obj,func) {
        var restaurantId=$(obj).val();

        var param = {restaurantId:restaurantId};
        $.getJSON("./api.php?m=Api&c=index&a=getRSRelated",param, function(data){
            if(data.status!=0){
                alert("数据获取失败，请稍后重试或联系管理员解决！");
            }else{
                $("#relatedStore").empty().append("<option value=\"0\">全部</option>");
                if(data.data) {
                    $.each(data.data, function (i, item) {
                        $("#relatedStore").append("<option value=\"" + i + "\">" + item + "</option>");
                    });
                }
            }
        });
    }

    //名单导出
    function exportData(){
        var exportUri = "<{U('Restaurant/monthRecord')}>";
        window.location.href = exportUri+'&export=1'
                +'&startDate='+$("#searchForm input[name='startDate']").val()
                +'&endDate='+$("#searchForm input[name='endDate']").val()
                +'&restaurant='+$("#searchForm select[name='restaurant']").val()
                +'&store='+$("#searchForm select[name='store']").val()
    }
</script>